/*
 * @Author: Yang Zhang
 * @Date: 2021-11-18 22:33:12
 * @LastEditors: Yang Zhang
 * @LastEditTime: 2021-12-07 18:23:12
 * @Description: 配置文件
 */

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import ViteComponents, { AntDesignVueResolver } from 'vite-plugin-components'

const path = require('path')

// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  resolve: {
    alias: [
      { find: 'vue', replacement: 'vue/dist/vue.esm-bundler.js' },
      { find: '@', replacement: path.resolve(__dirname, 'src') }
    ]
  },
  plugins: [
    vue(),
    ViteComponents({
      customComponentResolvers: [AntDesignVueResolver()]
    })
  ],
  css: {
    postcss: {
      plugins: [
        require('postcss-px2rem-exclude')({ remUnit: 192, exclude: /node_modules|folder_name/i })
      ]
    }
  },

  server: {
    open: true,
    host: '0.0.0.0',
    port: 9090,
    proxy: {
      // 选项写法
      '/store': {
        target: 'https://sell.socialpass.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/store/, '/store')
      },
      '/common': {
        target: 'https://sell.socialpass.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/common/, '/common')
      }
    }
  },
  build: {
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString()
          }
        }
      }
    },
    sourcemap: true
  }
})


